package java6681.string;

import java.util.Arrays;
import java.util.Scanner;

public class WordString6681 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入用空格分隔的一组词汇：");
        String line = sc.nextLine();
        String[] s = getWord6681(line.trim());
        System.out.println(Arrays.toString(s));
    }

    public static String[] getWord6681(String s) {
        String[] arr = new String[2];
        String start = "";
        String end = "";

       if (s.isEmpty()) {
           return null;
      }
        if (s.startsWith("  ") && s.endsWith("  ")) {
            return null;
        }

        if (s.indexOf(" ") == -1) {
            String[] arr1 = new String[1];
            arr1[0] = s;
            return arr1;
        }

        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == ' ') {
                break;
            } else {
                start += ch;
            }
        }
        StringBuilder sb = new StringBuilder(s);
        s = sb.reverse().toString();

        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == ' ') {
                break;
            } else {
                end += ch;
            }
        }
        StringBuilder sbb = new StringBuilder(end);
        end = sbb.reverse().toString();

        arr[0] = start;
        arr[1] = end;

        return arr;
    }
}